package com.tentative.competition.web.controller.schedule.service;

import com.tentative.competition.common.core.controller.BaseController;
import com.tentative.competition.common.core.domain.AjaxResult;
import com.tentative.competition.common.core.result.ApiResult;
import com.tentative.competition.common.core.result.PageResult;
import com.tentative.competition.common.model.schedule.param.AttendInfoAddParam;
import com.tentative.competition.common.model.schedule.resp.AttendInfoResp;
import com.tentative.competition.schedule.service.ScheduleAttendInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @auther: Smile Huang
 * @date: 2023/6/24 22:25
 * @desc:
 * @version: 2.0
 */
@Api(tags = "service-大赛业务")
@RestController
@RequestMapping("/service/attend")
public class AttendInfoController extends BaseController {

    @Autowired
    private ScheduleAttendInfoService attendInfoService;


    @ApiOperation("查询参赛列表-分页")
    @PostMapping("/list")
    public ApiResult list(@RequestBody AttendInfoAddParam param) {
        PageResult<AttendInfoResp> pageResult = attendInfoService.pageList(param);
        return ApiResult.ofPage(pageResult.getContent(),pageResult.getTotal());
    }

    /**
     * 作品明细
     * @param id
     * @return
     */
    @ApiOperation("获取参赛明细")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(attendInfoService.getInfo(id));
    }

    /**
     * 创建｜修改赛程信息
     * @param param
     * @return
     */
    @ApiOperation("创建｜修改参赛信息")
    @PostMapping("/add-edit")
    public AjaxResult addOrEdit(@RequestBody AttendInfoAddParam param) {
        attendInfoService.addOrEdit(param);
        return AjaxResult.success();
    }

    @ApiOperation("删除参赛信息")
    @PostMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(attendInfoService.deleteOrgInfo(ids));
    }

}
